// 
//  EVECDSkillPlanItem.m
//  EVE Mac Suite
//
//  Created by Vadim Lozko on 5/6/09.
//  Copyright 2009  __Vadim__. All rights reserved.
//

#import "EVECDSkillPlanItem.h"
#import "EVECDAbstractSkill.h"
#import "EVECDSkillPlan.h"
#import "EVECDLearnedSkill.h"
#import "EVECDSkill.h"
#import "EMSSkillTrainingInfo.h"

@implementation EVECDSkillPlanItem 

@dynamic position;
@dynamic trainingToLevel;
@dynamic primaryAttributeValue;
@dynamic secondaryAttributeValue;
@dynamic learnedSkill;
@dynamic partOfSkillPlan;

@end

@implementation EVECDSkillPlanItem (BindingsAccessors)

-(NSNumber*)trainingTime
{
	int skillPoints = self.learnedSkill.skillPointsLearned.intValue;
	int level = self.trainingToLevel.intValue;
	int rank = self.learnedSkill.skill.rank.intValue;
	int minimumPointsForPreviousLevel = [EMSSkillTrainingInfo skillPointsRequiredForLevel:(level - 1) rank:rank];
	if(skillPoints < minimumPointsForPreviousLevel)
	{
		skillPoints = minimumPointsForPreviousLevel;
	}	
	int skillPointsToNextLevel = [EMSSkillTrainingInfo skillPointsRequiredForLevel:level rank:rank] - skillPoints;
	double primaryAttributeValue = self.primaryAttributeValue.doubleValue;
	double secondaryAttributeValue = self.secondaryAttributeValue.doubleValue;
	return [NSNumber numberWithDouble:((skillPointsToNextLevel/(primaryAttributeValue + (secondaryAttributeValue/2))) * 60)];
}

-(NSNumber*)finishDate
{
	double previousItemFinishDate = [self.partOfSkillPlan previousPlannedSkillFinishDateFromSkillPlanItem:self].doubleValue;
	double selfTrainingTime = self.trainingTime.doubleValue;
	return [NSNumber numberWithDouble:(previousItemFinishDate + selfTrainingTime)];
}

@end